﻿package frEngine.loaders.away3dMd5
{
    import __AS3__.vec.*;
    import baseEngine.utils.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.loaders.resource.info.*;

    public class Skeleton extends Object
    {
        private var tracksCache:Dictionary;
        public var isOptimize:Boolean;
        public var hasScaledBone:Boolean = false;
        public var splitSurfaceInfo:SplitSurfaceInfo;
        public var maxJointCount:uint;
        public var magic:uint;
        public var hasNormal:Boolean;
        public var version:uint;
        public var material:String;
        public var meshUrl:String;
        private var _joinRoot:SkeletonJoint;
        public var inherits:Vector.<SkeletonJoint>;
        public var info:Md5MeshInfo;
        private var jointNameIndexMap:Dictionary;

        public function Skeleton(param1:Md5MeshInfo)
        {
            this.tracksCache = new Dictionary(false);
            this.inherits = new Vector.<SkeletonJoint>;
            this.info = param1;
            return;
        }// end function

        public function get numBones() : uint
        {
            return this.inherits.length;
        }// end function

        public function getBaseGlobleBone(param1:String) : Matrix3D
        {
            var _loc_2:* = this.jointFromName(param1);
            if (_loc_2)
            {
                return _loc_2.gobleTransform;
            }
            return null;
        }// end function

        public function getFrameList(param1:String, param2:String, param3:int) : Dictionary
        {
            var _loc_6:int = 0;
            var _loc_4:* = param1 + ":" + param2;
            var _loc_5:* = this.tracksCache[_loc_4];
            if (_loc_5 == null)
            {
                _loc_5 = new Dictionary(false);
                this.tracksCache[_loc_4] = _loc_5;
                _loc_6 = 0;
                while (_loc_6 < param3)
                {
                    
                    _loc_5[_loc_6] = new Array();
                    _loc_6++;
                }
                _loc_5["bone"] = new Array();
            }
            return _loc_5;
        }// end function

        public function set joinRoot(param1:SkeletonJoint) : void
        {
            this._joinRoot = param1;
            return;
        }// end function

        public function get joinRoot() : SkeletonJoint
        {
            var _loc_1:SkeletonJoint = null;
            if (!this._joinRoot)
            {
                for each (_loc_1 in this.inherits)
                {
                    
                    if (_loc_1.parentIndex == -1)
                    {
                        this._joinRoot = _loc_1;
                        break;
                    }
                }
            }
            return this._joinRoot;
        }// end function

        public function jointFromIndex(param1:int) : SkeletonJoint
        {
            if (param1 < this.inherits.length)
            {
                return this.inherits[param1];
            }
            return null;
        }// end function

        public function jointFromName(param1:String) : SkeletonJoint
        {
            var _loc_2:* = this.jointIndexFromName(param1);
            if (_loc_2 != -1)
            {
                return this.inherits[_loc_2];
            }
            return null;
        }// end function

        public function jointIndexFromName(param1:String) : int
        {
            var _loc_2:int = 0;
            var _loc_3:SkeletonJoint = null;
            if (!this.jointNameIndexMap)
            {
                this.jointNameIndexMap = new Dictionary(false);
                for each (_loc_3 in this.inherits)
                {
                    
                    this.jointNameIndexMap[_loc_3.name] = _loc_2;
                    _loc_2++;
                }
            }
            if (this.jointNameIndexMap[param1])
            {
                return this.jointNameIndexMap[param1];
            }
            return -1;
        }// end function

        public function dispose() : void
        {
            this.inherits.length = 0;
            this.tracksCache = new Dictionary(false);
            this.jointNameIndexMap = null;
            return;
        }// end function

    }
}
